#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main()
{
  
  int fd = open("log.txt", O_CREAT | O_TRUNC | O_WRONLY, 0644);
  if(fd < 0)
  {
    perror("open failed");
    return 1;
  }
  dup2(fd, 1);
  const char* str = "hello world by write\n";
  const char* str1 = "hello world by printf\n";
  const char* str2 = "hello world by fprintf\n";

  write(1, str, strlen(str));
  printf("%s",str1);
  fprintf(stdout,"%s",str2);
  
  fork();
  fflush(stdout);


  close(fd);


  return 0;
}
